
M.remoteStaticPathEnable=true;
M.remoteStaticPath="http://minglie.gitee.io/ming_api_mock_plugins/mi_mysql_client";

myDbconfig={
       "host"     : "127.0.0.1",
        "user"     : "root",
        "password" : "123456",
        "port"     : "3306",
        "database" : "miapi"
}

Db = M.getMySql(myDbconfig);


app.begin(async (req,res)=>{  
    console.log(req.url)
    if(req.url.startsWith("/M_database.js")){
        if (fs.existsSync(staticPath+"M_database.js")) {
            res.send(M.readFile(staticPath+"M_database.js"));
            return;
        }
    }

    if(req.isStaticRequest()){
        res.renderUrl(M.remoteStaticPath+req.url);
        return;
    }
})

app.get("/",async function (req,res) {
    res.renderUrl("http://minglie.gitee.io/ming_api_mock_plugins/mi_mysql_client/index.html");
});


app.get("/u.html",async function (req,res) {
    res.renderUrl("http://minglie.gitee.io/ming_api_mock_plugins/mi_mysql_client/u.html");
});

app.post("/doSql",async function (req,res) {
    try{      
        var rows= await Db.doSql(req.params.sql);
        res.send(M.result(rows));
      
    }catch (e){
        res.send(M.result(e,false));
    }
})
app.get("/getDataBaseName",async function (req,res) {
    res.send(M.result(myDbconfig.database) )
})
app.post("/groupConfig",async function (req,res) {
    M.writeFile("M_database.js","M_databaseJson="+req.body)
    res.send(M.result("ok") )
})

